/*

 Copyright (c) 2008-2009 Fabrizio Pistonesi

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

 */

#include "spherical.h"

Spherical::Spherical(IrrlichtDevice *device, s32 idn, stringc equiRect) : Node(device, idn, ENT_SPHERICAL)
  {
    if (!Device->getFileSystem()->existFile(equiRect.c_str()))
      {
        Device->getLogger()->log("Could not find the image: %S", equiRect.c_str());
        equiRect = "missing.png";
      }
    Equirect = equiRect;
    Texture = Device->getVideoDriver()->getTexture(equiRect.c_str());
    ThisNode = Device->getSceneManager()->addSkyDomeSceneNode(Texture,32,32,0.9f,2.0f,50.0f,this->Root);
    		//addSkyDomeSceneNode(Texture, 32, 32,1, 2, this->Root);
    ThisNode->setMaterialFlag(EMF_ANISOTROPIC_FILTER, true);
    ThisNode->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
    ThisNode->setIsDebugObject(true);
  }

Spherical::~Spherical()
  {
  }

f32 Spherical::getRotation()
  {
    return this->Root->getRotation().Y;
  }

void Spherical::setRotation(f32 degree)
  {
    ThisNode->setRotation(vector3df(0, degree, 0));
    Rotation = vector3d<f32> (0, degree, 0);
  }

void Spherical::reload(stringc equiRect)
  {
    ThisNode->drop();
    if (!Device->getFileSystem()->existFile(equiRect.c_str()))
      {
        Device->getLogger()->log("Could not find the image: %s", equiRect.c_str());
        equiRect = "missing.png";
      }
    Texture = Device->getVideoDriver()->getTexture(equiRect.c_str());
    ThisNode = Device->getSceneManager()->addSkyDomeSceneNode(Texture,32,32,0.9f,2.0f,50.0f,this->Root);
    		//addSkyDomeSceneNode(Texture, 32, 32, 1, 2, this->Root);
  }
